package com.leenmvc.core.security.entity.core;

import com.leenmvc.core.annotation.DbInfo;
import com.leenmvc.core.annotation.PrimaryKey;
import com.leenmvc.core.annotation.TableField;
import com.leenmvc.core.base.BaseEntity;
import com.leenmvc.core.security.entity.export.LogOperationExcel;
import com.leenmvc.core.utils.logger.LogEntity;

import java.util.Date;

/**
 * 操作日志
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2019-12-24
 */

@DbInfo(value = "sys_log_operation", excelEntity = LogOperationExcel.class, comment = "操作日志")
public class SysLogOperation extends BaseEntity implements LogEntity {

    @PrimaryKey
    private Long id;

    /**
     *
     */
	private String operation;
    /**
     *
     */
	private String requestUri;
    /**
     *
     */
	private String requestMethod;
    /**
     *
     */
	private String requestParams;
    /**
     *
     */
	private Object requestBody;

    /**
     * 请求结果
     */
	private String requestResult;
    /**
     *
     */
	private Integer requestTime;
    /**
     *
     */
	private String userAgent;
    /**
     *
     */
	private String ip;

	@TableField(false)
	private String contentType;
    /**
     *
     */
	private Integer status;
    /**
     *
     */
	private String creatorName;

    private Date createDate;

    private Long creator;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getOperation() {
        return operation;
    }

    public void setOperation(String operation) {
        this.operation = operation;
    }

    public String getRequestUri() {
        return requestUri;
    }

    public void setRequestUri(String requestUri) {
        this.requestUri = requestUri;
    }

    public String getRequestMethod() {
        return requestMethod;
    }

    public void setRequestMethod(String requestMethod) {
        this.requestMethod = requestMethod;
    }

    public String getRequestParams() {
        return requestParams;
    }

    public void setRequestParams(String requestParams) {
        this.requestParams = requestParams;
    }

    public Integer getRequestTime() {
        return requestTime;
    }

    public void setRequestTime(Integer requestTime) {
        this.requestTime = requestTime;
    }

    public String getUserAgent() {
        return userAgent;
    }

    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getCreatorName() {
        return creatorName;
    }

    public void setCreatorName(String creatorName) {
        this.creatorName = creatorName;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Long getCreator() {
        return creator;
    }

    public void setCreator(Long creator) {
        this.creator = creator;
    }

    public Object getRequestBody() {
        return requestBody;
    }

    public void setRequestBody(Object requestBody) {
        this.requestBody = requestBody;
    }

    public String getRequestResult() {
        return requestResult;
    }

    public void setRequestResult(String requestResult) {
        this.requestResult = requestResult;
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    @Override
    public SysLogOperation clean() {
        this.id = null;
        this.operation = null;
        this.requestUri = null;
        this.requestMethod = null;
        this.requestParams = null;
        this.requestBody = null;
        this.requestTime = null;
        this.userAgent = null;
        this.ip = null;
        this.status = null;
        this.creatorName = null;
        this.createDate = null;
        this.creator = null;
        return this;
    }

    /**
     * 将log转成
     *
     * @return
     */
//    public RequestForTest logToRequest() {
//        RequestForTest requestForTest = new RequestForTest();
//        if(this.getRequestBody() != null && !"null".equals(this.getRequestBody())) {
//            requestForTest.setBody(this.getRequestBody());
//        }
//        requestForTest.setNote(this.getOperation());
//        requestForTest.setUrl(this.getRequestUri().replace("/springboot", "").replaceAll("^\\/+", ""));
//        requestForTest.setMethod(this.getRequestMethod().toLowerCase());
//
//        if(this.contentType != null && !"null".equals(this.contentType)) {
//            requestForTest.setContentType(this.contentType);
//        }
//        if(this.getRequestParams() != null && !"null".equals(this.getRequestParams())) {
//            requestForTest.setParams(this.getRequestParams());
//        }
//        return requestForTest;
//    }
}
